//...
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int n, x, y, i, sum;
priority_queue<int> q;
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	scanf("%d", &n);
	for(i=0;i<n;++i){
		scanf("%d", &x);
		q.push(-x);
	}
	sum=0;
	while(q.size()>1){
		x=-q.top();q.pop();
		y=-q.top();q.pop();
		sum+=x+y;
		q.push(-(x+y));
		//printf("%d %d  =  %d\n", x, y, sum);
	}
	printf("%d\n", sum);
	
	
	return 0;
}
